package controllers;

import java.util.*;

import play.Play;
import play.mvc.*;

import models.*;
import play.db.jpa.Blob;
import play.db.jpa.Model;
 
import javax.persistence.*;

/**
 * Super class for Club and Retailer controllers. Club and Retailer controllers 
 * have so much things in common, that the common stuff should be here, not 
 * copy-pasted to both controllers.
 *
 */
public class ConnectedUser extends Application {
	
	@OneToMany(mappedBy="discountCreator", cascade=CascadeType.ALL)
	public List<Discount> discounts;
	
	@Before static void isConnected() {
		if(connectedUser == null) {
			flash.error("You're not allowed to access requested page. Please login first.");
			Application.login();
		}
	}
	
	@Before
	public static void newDiscountCount() {
		if(connectedUser != null){
			renderArgs.put("discountsWaitingCount", connectedUser.getDiscountsWaitingApproval().size());
		}
	}
	
	protected static void renderDiscounts() {
    	// List<models.Discount> activeDiscounts = connectedUser.getActiveDiscounts();
    	
    	// renderTemplate("Discount/list.html", activeDiscounts);
    }

}
